package com.cj.rxdo;

import android.content.res.Resources;
import android.graphics.Color;
import android.os.Handler;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.LinearLayout;

import com.qiyukf.unicorn.activity.ServiceMessageFragment;
import com.qiyukf.unicorn.api.ConsultSource;
import com.qiyukf.unicorn.api.Unicorn;
import com.trello.rxlifecycle.android.ActivityEvent;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import java.util.concurrent.TimeUnit;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import in.srain.cube.views.ptr.PtrClassicDefaultHeader;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;
import in.srain.cube.views.ptr.PtrUIHandler;
import in.srain.cube.views.ptr.header.MaterialHeader;
import in.srain.cube.views.ptr.header.StoreHouseHeader;
import rx.Observable;
import rx.Observer;
import rx.Subscriber;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
import rx.functions.Action0;
import rx.functions.Action1;
import rx.functions.Func1;
import rx.schedulers.Schedulers;

public class MainActivity extends RxAppCompatActivity {
    @BindView(R.id.btn)Button btn;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ButterKnife.bind(this);

    }

    @OnClick(R.id.btn)
    void setBtn(){
        ConsultSource source=new ConsultSource("comeFromMain","TTTTTITLE","Custom");
//        LinearLayout ll= new LinearLayout(this);
//        ServiceMessageFragment fragment=Unicorn.newServiceFragment("comFromMain",source,ll);
//        FragmentTransaction transaction=getSupportFragmentManager().beginTransaction();
//                transaction.replace(R.id.ysf_title_bar_actions_layout,fragment);
//        try{
//            transaction.commitAllowingStateLoss();
//        }catch (Exception e){
//
//        }
        Unicorn.openServiceActivity(this,"SecondTitle",source);
    }

    private Subscription sb;
    @OnClick(R.id.btn_1)
    void setBtn1(final Button btn1){
        Observable ob1=Observable.interval(0,2,TimeUnit.SECONDS,Schedulers.io());
        Observable ob2=Observable.interval(0,3,TimeUnit.SECONDS,Schedulers.io());
        Observable.interval(0,2,TimeUnit.SECONDS)
                .compose(this.<Long>bindUntilEvent(ActivityEvent.PAUSE))
                .compose(new Tranf())
                .observeOn(Schedulers.io())
                .subscribe(new Observer<String>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onNext(String s) {
                        Log.d("xx",s);
                    }
                });
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
    }
}
